home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / dh_installxmlcatalogs < prev    next >
Encoding:
Text File  |  2008-11-06  |  9.2 KB  |  290 lines

  1. #!/usr/bin/perl -w
  2. ## ----------------------------------------------------------------------
  3. ## Debian dh_installxmlcatalogs
  4. ## ----------------------------------------------------------------------
  5. ## Copyright (c) 2004 Ardo van Rangelrooij, Adam Di Carlo
  6. ##
  7. ## This is free software; see the GNU General Public Licence version 2
  8. ## or later for copying conditions.  There is NO warranty.
  9. ## ----------------------------------------------------------------------
  10.  
  11. =head1 NAME
  12.  
  13. dh_installxmlcatalogs - install and register XML catalog files
  14.  
  15. =head1 SYNOPSIS
  16.  
  17. B<dh_installxmlcatalogs> [S<I<debhelper options>>] [B<-n>]
  18.  
  19. =head1 DESCRIPTION
  20.  
  21. B<dh_installxmlcatalogs> is a debhelper program that installs and
  22. registers XML catalog files.  It complies with the Debian XML/SGML
  23. policy.
  24.  
  25. The file F<debian/I<package>.xmlcatalogs> lists the local XML catalog
  26. files to be installed per package as well as the XML entities in those
  27. local XML catalog files that are to be registered in the XML catalog
  28. system.
  29.  
  30. The local XML catalog file entries in that file should be of the form
  31. C<local;source;dest>, where the verbatim C<local> indicates this is an
  32. entry for a local XML catalog file, C<source> indicates where the
  33. local XML catalog resides in the source tree, and C<dest> indicates
  34. the destination location for the local XML catalog under the package
  35. build area.  C<dest> should start with F</usr/share/xml/>.
  36.  
  37. The entries for the XML entities to be registered in the package XML
  38. catalog file should be of the form C<package;type;id;catalog>, where
  39. the verbatim C<package> indicates this is an entry for an XML entity
  40. to be registered in the package XML catalog file, C<type> indicates
  41. the XML entity type (public, system, uri), C<id> indicates the XML
  42. entity id, and C<catalog> indicates the local XML catalog file.
  43.  
  44. The entries for the XML entities to be registered in the root XML
  45. catalog file should be of the form C<root;type;id>, where the verbatim
  46. C<root> indicates this is an entry for an XML entity to be registered
  47. in the root XML catalog file, C<type> indicates the XML entity type
  48. (public, system, uri), and C<id> indicates the XML entity id.
  49.  
  50. If an entry for is to be registered identically in the root catalog
  51. and the package catalog file, you can use the form
  52. C<root-and-package;type;id;catalog>, where the verbatim
  53. C<root-and-package> indicates this is an entry for an XML entity to be
  54. registered in both the root and package XML catalog files, C<type>
  55. indicates the XML entity type (public, system, uri), C<id> indicates
  56. the XML entity id, and C<catalog> indicates the local XML catalog
  57. file.
  58.  
  59. XML entity types are described in L<update-xmlcatalog(8)>.  Using the
  60. C<root> or C<package> commands, a type of C<public> will general
  61. C<delegatePublic> statements in the applicable catalog file. Generally
  62. you will want to use the types C<public> for any formal public
  63. identifiers, and C<system> for any files on the local filesystem or
  64. URLs.  C<uri> is only used for non-local files which are not part of
  65. the external document subset, e.g., they are not used for entities or
  66. DTDs.
  67.  
  68. B<dh_installxmlcatalogs> automatically adds maintainer script snippets
  69. for the registration and unregistration of the listed XML entities in
  70. the XML catalog system (unless B<-n> is used).    A dependency on the
  71. B<xml-core> package will be added to C<${misc:Depends}>, so be sure to
  72. use that variable in the file F<debian/control>.  See
  73. L<dh_installdeb(1)> for an explanation of Debhelper maintainer script
  74. snippets.
  75.  
  76. =head1 OPTIONS
  77.  
  78. =over 4
  79.  
  80. =item B<-n>, B<--noscripts>
  81.  
  82. Do not modify F<postinst>/F<postrm>/F<prerm> scripts.
  83.  
  84. =back
  85.  
  86. =head1 NOTES
  87.  
  88. Note that this command is not idempotent. "dh_clean -k" should be
  89. called between invocations of this command. Otherwise, it may cause
  90. multiple instances of the same text to be added to maintainer scripts.
  91.  
  92. =head1 SEE ALSO
  93.  
  94. L<debhelper(7)>
  95.  
  96. F</usr/share/doc/xml-core/>
  97.  
  98. =head1 AUTHOR
  99.  
  100. B<Ardo van Rangelrooij> E<lt>ardo@debian.orgE<gt>
  101.  
  102. B<Adam Di Carlo> E<lt>aph@debian.orgE<gt>
  103.  
  104. =cut
  105.  
  106. ## ----------------------------------------------------------------------
  107. use strict;
  108.  
  109. ## ----------------------------------------------------------------------
  110. use Debian::Debhelper::Dh_Lib;
  111.  
  112. ## ----------------------------------------------------------------------
  113. my $xmlcorever    = "0.12";
  114.  
  115. ## ----------------------------------------------------------------------
  116. my $debug_update_xmlcatalog = 0;
  117.  
  118. ## ----------------------------------------------------------------------
  119. init();
  120.  
  121. ## ----------------------------------------------------------------------
  122. sub add_xmlcat_cmd ($$$;$) {
  123.     my ($pkg, $type, $id, $local) = @_;
  124.     my $cmd = 'update-xmlcatalog';
  125.     $cmd .= ' --add';
  126.     $cmd .= " --type $type";
  127.     $cmd .= " --id \\\"$id\\\"";
  128.     $cmd .= " --package $pkg";
  129.     if ( $local ) {
  130.     $cmd .= " --local $local";
  131.     } else {
  132.     $cmd .= " --root";
  133.     }
  134.     $debug_update_xmlcatalog and $cmd .= ' --verbose';
  135.     return $cmd;
  136. }
  137.  
  138. ## ----------------------------------------------------------------------
  139. sub del_xmlcat_cmd ($$$;$) {
  140.     my ($pkg, $type, $id, $root) = @_;
  141.     my $cmd = 'update-xmlcatalog';
  142.     $cmd .= ' --del';
  143.     $cmd .= " --type $type";
  144.     $cmd .= " --id \\\"$id\\\"";
  145.     if ( $root ) {
  146.     $cmd .= " --root";
  147.     } else {
  148.         $cmd .= " --package $pkg";
  149.     }
  150.     $debug_update_xmlcatalog and $cmd .= ' --verbose';
  151.     $cmd .= ' || true';
  152.     return $cmd;
  153. }
  154.  
  155. ## ----------------------------------------------------------------------
  156. foreach my $package (@{$dh{DOPACKAGES}}) {
  157.  
  158.     if ($#ARGV >= 0) {
  159.         error("extra command-line arguments");
  160.     }
  161.  
  162.     my $tmpdir = tmpdir($package);
  163.  
  164.     my $xmlcatlistfile = pkgfile( $package, "xmlcatalogs" );
  165.  
  166.     if ( $xmlcatlistfile ) {
  167.  
  168.         my @xml_data = ();
  169.  
  170.         open ( DH_FARRAY_IN, $xmlcatlistfile )
  171.             || error( "cannot read $xmlcatlistfile: $1" );
  172.         while ( <DH_FARRAY_IN> ) {
  173.             chomp;
  174.             s/#.*//;
  175.             s/^\s+//;
  176.             s/\s+$//;
  177.             next unless length;
  178.             my @line = split( /;/ );
  179.             push( @xml_data, [@line] );
  180.         }
  181.         close( DH_FARRAY_IN );
  182.  
  183.         my $packagecat    = "/etc/xml/$package.xml";
  184.         my $ADD_PACKAGE = '';
  185.         my $ADD_ROOT    = '';
  186.         my $DEL_PACKAGE = '';
  187.         my $DEL_ROOT    = '';
  188.  
  189.         foreach my $line ( @xml_data ) {
  190.  
  191.             if ( $line->[0] eq 'local' ) {
  192.  
  193.                 my $source = $line->[1];
  194.                 my $dest = $line->[2];
  195.  
  196.                 my $fulldest = "$tmpdir/$dest"; 
  197.                 $fulldest =~ s|//|/|g; # beautification
  198.     
  199.                 if ( ! -d dirname( $fulldest ) ) {
  200.                     doit( "install", "-d", "-m755",
  201.                     $tmpdir . "/" . dirname( $dest ) );
  202.                 }
  203.  
  204.                 doit( "install", "-p", "-m644", $source, $fulldest );
  205.  
  206.             } elsif ( $line->[0] eq 'package' ) {
  207.                 if ( ! $dh{ NOSCRIPTS } ) {
  208.  
  209.                     my $type  = $line->[1];
  210.                     my $id      = $line->[2];
  211.                     my $local = $line->[3];
  212.  
  213.                     if ( ! $local ) {
  214.                         die("error: package command with ID '$id' incorrect, must specify local catalog\n");
  215.                     } elsif ( ! -f "$tmpdir/$local" ) {
  216.                         die("error: package command with ID '$id' uses non-existent catalog '$local'\n");
  217.                     }
  218.                     
  219.                     $ADD_PACKAGE .= "\t" . add_xmlcat_cmd($package, $type, $id, $local) . "\\n";
  220.                     $DEL_PACKAGE .= "\t" . del_xmlcat_cmd($package, $type, $id) . "\\n";
  221.  
  222.                 }
  223.             } elsif ( $line->[0] eq 'root' ) {
  224.                 if ( ! $dh{ NOSCRIPTS } ) {
  225.  
  226.                     my $type = $line->[1];
  227.                     my $id     = $line->[2];
  228.                     $ADD_ROOT .= "\t" . add_xmlcat_cmd($package, $type, $id) . "\\n";
  229.                     $DEL_ROOT .= "\t" . del_xmlcat_cmd($package, $type, $id, 1) . "\\n";
  230.  
  231.                 }
  232.             } elsif ( $line->[0] eq 'root-and-package' ) {
  233.                 if ( ! $dh{ NOSCRIPTS } ) {
  234.  
  235.                     my $type = $line->[1];
  236.                     my $id     = $line->[2];
  237.                     my $local = $line->[3];
  238.  
  239.                     if ( ! $local ) {
  240.                         die("error: root-and-package command with ID '$id' incorrect, must specify local catalog\n");
  241.                     } elsif ( ! -f "$tmpdir/$local" ) {
  242.                         die("error: root-and-package command with ID '$id' uses non-existent catalog '$local'\n");
  243.                     }
  244.  
  245.                     $ADD_PACKAGE .= "\t" . add_xmlcat_cmd($package, $type, $id, $local) . "\\n";
  246.                     $DEL_PACKAGE .= "\t" . del_xmlcat_cmd($package, $type, $id) . "\\n";
  247.                     $ADD_ROOT    .= "\t" . add_xmlcat_cmd($package, $type, $id) . "\\n";
  248.                     $DEL_ROOT    .= "\t" . del_xmlcat_cmd($package, $type, $id, 1) . "\\n";
  249.  
  250.                 }
  251.             } else {
  252.                 die("cannot understand command '" . $line->[0] . 
  253.                     "' in file $xmlcatlistfile\n");
  254.             }
  255.         }
  256.  
  257.         # sanity checking
  258.         if ( $ADD_PACKAGE and not $ADD_ROOT ) {
  259.             warn("warning: elements added to package XML catalog, but not entry for root catalog\n");
  260.         }
  261.  
  262.         if ( not $ADD_PACKAGE and not $ADD_ROOT ) {
  263.             warning("warning: no catalogs registered\n");
  264.         } else {
  265.  
  266.             $ADD_PACKAGE or $ADD_PACKAGE = "\t:";
  267.             $ADD_ROOT    or $ADD_ROOT    = "\t:";
  268.             $DEL_PACKAGE or $DEL_PACKAGE = "\t:";
  269.             $DEL_ROOT    or $DEL_ROOT    = "\t:";
  270.             autoscript( $package, "postinst", "postinst-xmlcatalog",
  271.                     "s%#ADD_PACKAGE#%$ADD_PACKAGE%g; s%#ADD_ROOT#%$ADD_ROOT%g;" );
  272.             autoscript( $package, "prerm", "prerm-xmlcatalog",
  273.                     "s%#DEL_PACKAGE#%$DEL_PACKAGE%g; s%#DEL_ROOT#%$DEL_ROOT%g;" );
  274.             autoscript( $package, "postrm", "postrm-xmlcatalog",
  275.                     "s%#PACKAGECAT#%$packagecat%g;" );
  276.  
  277.             addsubstvar( $package,
  278.                      "misc:Depends", "xml-core", ">= $xmlcorever" );
  279.  
  280.             # Make sure /etc/xml exists (see http://bugs.debian.org/411770).
  281.             if (! -d "$tmpdir/etc/xml") {
  282.                 doit("install","-d","-m755","$tmpdir/etc/xml");
  283.             }
  284.  
  285.         }
  286.     }
  287. }
  288.  
  289. ## ----------------------------------------------------------------------
  290.